/*
 * Author: 李波(Edwin Lee)
 * Date: 2024-08-07 04:31:08
 * FilePath: /mprpc/src/mprpcapplication.cc
 * LastEditTime: 2024-08-12 02:30:53
 * version: 1.0
 * Description: 
 */
#include "mprpcapplication.h"

#include <iostream>
#include <unistd.h>
MprpcConfig MprpcApplication::config_;
void MprpcApplication::showArgsHelp()
{
    std::cout << "formate: command -i <configfile>" << std::endl;
}

void MprpcApplication::init(int argc,char** argv)
{
    if(argc < 2)
    {
        showArgsHelp();
        exit(EXIT_FAILURE);
    }

    int c = 0;
    std::string config_file;
    while((c = getopt(argc, argv, "i:")) != -1)
    {
        switch(c)
        {
        case 'i':
            config_file = optarg;
            break;
        case '?':
            showArgsHelp();
            exit(EXIT_FAILURE);
        case ':':
            showArgsHelp();
            exit(EXIT_FAILURE);
        default:
            break;

        }
    }

    // 开始加载配置文件 rpcser_ip rpcserver_port zookeeper_ip zookeeper_port
    config_.loadConfigFile(config_file.c_str());
    
    std::cout << "rpcserverip:\t"<<config_.load("rpcserverip")<<std::endl;
    std::cout << "rpcserverport:\t" << config_.load("rpcserverport") << std::endl;
    std::cout << "zookeeperip:\t" << config_.load("zookeeperip") << std::endl;
    std::cout << "zookeeperport:\t" << config_.load("zookeeperport") << std::endl;
}

MprpcApplication& MprpcApplication::getInstance()
{
    static MprpcApplication app;
    return app;
}

MprpcConfig& MprpcApplication::getConfig()
{
    return config_;
}